//
//  photo12Cell.m
//  GolfFriend
//
//  Created by Vescky on 14-3-5.
//  Copyright (c) 2014年 vescky.org. All rights reserved.
//

#import "photo12Cell.h"
#import "UIImageView+MJWebCache.h"
#import "MJPhotoBrowser.h"
#import "MJPhoto.h"

@interface photo12Cell () {
    NSMutableDictionary *photoCellcontent;
}
@end

@implementation photo12Cell

@synthesize delegate;

- (void)setDataInfo:(NSDictionary*)dict {
    photoCellcontent = [[NSMutableDictionary alloc] initWithDictionary:dict];
    labelTime.text = [photoCellcontent objectForKey:@"date"];
    [imgvContent setImageURLStr:GetQiniuResizeImageLink([photoCellcontent objectForKey:@"link"], 640) placeholder:Default_Image_Normal];
    [imgvContent addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)]];
}

- (IBAction)btnAction:(id)sender {
    if ([delegate respondsToSelector:@selector(photo12CellButtonDidPress:imageContent:)]) {
        [delegate photo12CellButtonDidPress:sender imageContent:imgvContent.image];
    }
    UIButton *btn = (UIButton*)sender;
    if (btn.tag == 101) {
        //下载
        NSLog(@"下载");
    }
    else if (btn.tag == 102) {
        //分享
        NSLog(@"分享");
    }
    else if (btn.tag == 103) {
        //分享
        NSLog(@"放大图片");
        [self tapImage:nil];
    }
}

- (void)tapImage:(UITapGestureRecognizer *)tap
{
    // 1.封装图片数据
    NSMutableArray *photos = [NSMutableArray arrayWithCapacity:1];
    MJPhoto *photo = [[MJPhoto alloc] init];
    photo.url = [NSURL URLWithString:[photoCellcontent objectForKey:@"link"]]; // 图片路径
    photo.srcImageView = imgvContent; // 来源于哪个UIImageView
    [photos addObject:photo];
    
    // 2.显示相册
    MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
    browser.currentPhotoIndex = 0; // 弹出相册时显示的第一张图片是？
    browser.photos = photos; // 设置所有的图片
    [browser show];
}


@end
